class_name UnitBigTurtle
extends UnitFlyMagic


func shoot_magic():
	if not attack_target: return
	
	for index in range(3):
		shoot_water_bullet_magic()
		await get_tree().create_timer(0.5).timeout


func shoot_water_bullet_magic():
	if not attack_target: return
	
	var target_unit = attack_target as UnitBase
	var target_position = ray_cast_point.global_position
	var target_dir = (attack_target.ray_cast_point.global_position - ray_cast_point.global_position).normalized()
	var magic = (ResourceManager.get_resource("particle_water_bullet") as PackedScene).instantiate() as ParticleWaterBullet
	
	var config = unit_data.config 
	magic.attack = config.main_attack
	magic.critical_rate = config.main_critical_attack_rate
	magic.critical_bonus = config.main_critical_attack_bonus
	magic.knockback = config.main_attack_knockback
	magic.sender = self
	var dir = target_dir
	magic.dir = dir
	magic.speed = 100
	magic.life_time = 3.0
	
	if config.main_attack_cam_shake:
		magic.hit_cam_shake_strength = config.main_attack_cam_shake_intensity
		magic.hit_cam_shake_duration = config.main_attack_cam_shake_duration
	
	level.particles_parent.add_child(magic)
	magic.global_position = target_position
	magic.set_is_enemy(true)
	#magic.set_collision_2_ground(false)


func play_magic_animation():
	animation_player.play("magic")
